<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

	class Durak extends CI_Controller 
	{
	

		function __construct()
	    {
		    parent::__construct();
		   	$this->load->model('user');
		   	$this->load->model('cards');
	   	}

		public function index()
		{
			 $data['content'] = 'login';
	         $this->load->view('include/template' ,$data);		
			//$this->load->view('welcome_message');
		}

		public function register()
		{
			 $data['content'] = 'register'; 
	         $this->load->view('include/template' ,$data);	
		}	

		public function main()
		{

			if($this->session->userdata('user_id'))
			{	
				 $this->online($this->session->userdata('user_id'));
				 $data['content'] = 'main';
		         $this->load->view('include/template' ,$data);	
	        }
	        else
	        {
	        	redirect('durak', 'refresh');
	        }
		}	

		public function logout()
		{	

			  $this->offline($this->session->userdata('user_id'));
			  $this->session->unset_userdata('user_id');			  
			  redirect('durak', 'refresh');
		}

		function online($id)
		{
			write_file($this->config->item('dir').$id.'.stat', '');
		}

		function offline($id)
		{
			unlink($this->config->item('dir').$id.'.stat');
		}

		function guest()
		{
			 $data['content'] = 'play_guest'; 
	         $this->load->view('include/template' ,$data);	
		}


		function cards_list_results()
		{
			$data = $this->cards->get_list_of_cards();
			shuffle($data);
			
			echo json_encode($data);
		}

	}

?>
